package IDSNN_1_Data;




 
import java.io.*;
import java.lang.*;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
 *
 * @author blacktigeriii
 */
public class Ficheiro {

    private BufferedReader entrada;
    private File ficheiroLei;
    private File ficheiroEsc;
    private String [] coisas;
    private ArrayList<String> dic;
    private Writer escrever;
    private int count, count1;
    private String dir;
    
    public Ficheiro(){
        dic=new ArrayList<String>();
        coisas = new String [100];
        dir = System.getProperty("user.dir");
    }
    
    public void buscarPalavras(String Ficheiro, int coun) throws IOException{
    count=coun;
    count1=0;   
    ficheiroLei = new File(Ficheiro);
    String linha;
    entrada = new BufferedReader (new InputStreamReader(new FileInputStream(Ficheiro)));
    while((linha=entrada.readLine())!=null)
        {
            dic.add(linha);
            //coisas[count]=linha;
            count++;
        }
   
    while(count1<count)
        {
            System.out.println(dic.get(count1));
            count1++;
        }
    }
    
    public void escrever(String dado) throws IOException{
    ficheiroEsc = new File(dir+"/Config.txt");
    escrever = new BufferedWriter(new FileWriter(ficheiroEsc));
    escrever.write(dado);
    escrever.close();      
    }
    
    public ArrayList<String> getLista(){
        return dic;
    }
    
    public String getDir(){
        return dir;
    }

    public void escreverArray(ArrayList<float[]> object) {
        ObjectOutputStream oos = null;
        try {
            oos = new ObjectOutputStream(new FileOutputStream(dir + "/temp.tmp", true));
            oos.writeObject(object);
            oos.close();
        } catch (IOException ex) {
            Logger.getLogger(Ficheiro.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                oos.close();
            } catch (IOException ex) {
                Logger.getLogger(Ficheiro.class.getName()).log(Level.SEVERE, null, ex);
            }
        }


}
public void clearDic(){
    dic.clear();
}
    
    
    public void apagar(){
    // A File object to represent the filename
    File f = new File(dir+"/temp.tmp");

    // Make sure the file or directory exists and isn't write protected
    try{
    if (!f.exists())
      


    // If it is a directory, make sure it is empty
    if (f.isDirectory()) {
      String[] files = f.list();
      if (files.length > 0)
        throw new IllegalArgumentException(
            "Delete: directory not empty: temp.tmp");
    }

    // Attempt to delete it
    boolean success = f.delete();

    }
    catch(Exception e){System.out.println(e+"");}
  }

}
